home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / dev / lang / python020.lha / python / lib / test / test_rgbimg.py < prev    next >
Text File  |  1995-10-22  |  1KB  |  50 lines

  1. # Testing rgbimg module
  2.  
  3. import rgbimg, os
  4.  
  5. error = 'test_rgbimg.error'
  6.  
  7. print 'RGBimg test suite:'
  8.  
  9. def findfile(file):
  10.     if os.path.isabs(file): return file
  11.     import sys
  12.     for dn in sys.path:
  13.         fn = os.path.join(dn, file)
  14.         if os.path.exists(fn): return fn
  15.     return file
  16.  
  17. def testimg(rgb_file, raw_file):
  18.     rgb_file = findfile(rgb_file)
  19.     raw_file = findfile(raw_file)
  20.     width, height = rgbimg.sizeofimage(rgb_file)
  21.     rgb = rgbimg.longimagedata(rgb_file)
  22.     if len(rgb) != width * height * 4:
  23.         raise error, 'bad image length'
  24.     raw = open(raw_file, 'r').read()
  25.     if rgb != raw:
  26.         raise error, 'images don\'t match for '+rgb_file+' and '+raw_file
  27.     for depth in [1, 3, 4]:
  28.         rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
  29.     os.unlink('@.rgb')
  30.  
  31. ttob = rgbimg.ttob(0)
  32. if ttob != 0:
  33.     raise error, 'ttob should start out as zero'
  34.  
  35. testimg('test.rgb', 'test.rawimg')
  36.  
  37. ttob = rgbimg.ttob(1)
  38. if ttob != 0:
  39.     raise error, 'ttob should be zero'
  40.  
  41. testimg('test.rgb', 'test.rawimg.rev')
  42.  
  43. ttob = rgbimg.ttob(0)
  44. if ttob != 1:
  45.     raise error, 'ttob should be one'
  46.  
  47. ttob = rgbimg.ttob(0)
  48. if ttob != 0:
  49.     raise error, 'ttob should be zero'
  50.